package com.ideaaedi.zoo.example.springboot.seata_dynamicds_sharding.alpha.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds_sharding.alpha.mapper.PayRecordMapper;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds_sharding.alpha.mapper.TransRecordMapper;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds_sharding.alpha.po.sharding.PayRecordPO;
import com.ideaaedi.zoo.example.springboot.seata_dynamicds_sharding.alpha.po.sharding.TransRecordPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BizShardingService {
    
    @Resource
    TransRecordMapper transRecordMapper;
    
    @Resource
    PayRecordMapper payRecordMapper;
    
    @DS("shardingAlpha")
    @Transactional(rollbackFor = Exception.class)
    public void insertSomeShardingData() {
        // 插入数据
        transRecordMapper.insert(TransRecordPO.builder()
                .id(IdWorker.getId())
                .transDate("2024-08-24")
                .remark("Alpha 备注A")
                .build());
        payRecordMapper.insert(PayRecordPO.builder()
                .id(IdWorker.getId())
                .payDate("2024-08-24")
                .amount("Alpha 5.7")
                .build());
    
        transRecordMapper.insert(TransRecordPO.builder()
                .id(IdWorker.getId())
                .transDate("2024-09-11")
                .remark("Alpha 备注B")
                .build());
        payRecordMapper.insert(PayRecordPO.builder()
                .id(IdWorker.getId())
                .payDate("2024-09-11")
                .amount("Alpha 1.8")
                .build());
    }
}
